import time
import requests
from selenium import webdriver
from selenium.webdriver import ActionChains

driver = webdriver.Chrome("D:/download_soft/chromedriver-win64/chromedriver-win64/chromedriver.exe")
driver.maximize_window()  # 窗口最大化

url = "https://www.bilibili.com/"
driver.get(url)  # 打开网页

# 获取登录节点
login = driver.find_element_by_class_name("header-login-entry")
login.click()  # 点击节点

time.sleep(2)  # 强制等待 2秒钟
# 获取账户节点
account = driver.find_element_by_css_selector("div.login-pwd-wp input[type='text']")
account.send_keys("wefjaselfdjsadf")  # 输入账户信息

password = driver.find_element_by_css_selector("div.login-pwd-wp input[type='password']")
password.send_keys("23434")  # 输入密码信息

# 获取登录按钮
login2 = driver.find_element_by_class_name("btn_primary")
login2.click()

time.sleep(2)
# geetest = driver.find_element_by_class_name("geetest_widget")
# geetest.screenshot("geetest.png")

geetest = driver.find_element_by_css_selector("div.geetest_item_wrap")
background_image = geetest.value_of_css_property("background-image")

image_url = background_image.replace('url("', '').replace('")', '').split("?")[0]

# 获取图片内容
content = requests.get(image_url).content

with open("geetest.png", "wb") as fp:
    fp.write(content)


from chaojiying import Chaojiying_Client

chaojiying = Chaojiying_Client('friendship123', 'asdf1234', '935797')	#用户中心>>软件ID 生成一个替换 96001
im = open('geetest.png', 'rb').read()													#本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
pic_str = chaojiying.PostPic(im, 9004)["pic_str"]

positions = []
for item in pic_str.split("|"):
    positions.append(item.split(","))

for position in positions:
    x = int(int(position[0])*0.88)
    y = int(int(position[1])*0.88)
    ActionChains(driver).move_to_element_with_offset(geetest, x, y).click().perform()
    time.sleep(1)

# 获取确认节点
commit = driver.find_element_by_css_selector("div.geetest_commit_tip")
commit.click()







